package com.example.demo.admin.service;/**
 * Created by kete on 2017-10-24.
 */

import com.example.demo.admin.vo.UserIndexInputVo;
import com.example.demo.admin.vo.UserIndexOutputVo;
import com.example.demo.common.persistence.dao.MenuDao;
import com.example.demo.core.ztree.MenuNode;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：kete
 * 创建时间：2017-10-24 14:18
 * 功能描述：
 * 版本：
 */
@RestController
public class MenuServiceImpl implements MenuService {


    @Autowired
    MenuDao menuDao;


    @Override
    @RequestMapping(value = "/menu/getMenuTitle")
    public UserIndexOutputVo getMenuTitle(UserIndexInputVo inputVo) {
        UserIndexOutputVo outputVo = new UserIndexOutputVo();

        List<Integer> roleIds = inputVo.getRoleIds();
        if(roleIds == null || roleIds.size() == 0){
            roleIds = Lists.newArrayList();
            roleIds.add(1);
        }

        List<MenuNode> menus = menuDao.getMenusByRoleIds(roleIds);

        outputVo.setMenus(MenuNode.buildTitle(menus));

        return outputVo;
    }
}
